#include "Sentence.h"

vector<vector<Phrase*>> Sentence::phrases;
bool Sentence::init = false;

Phrase* Phrase::CreatePhrase(string aPhrase)
{
	Phrase* p = new Phrase;
	p->phrase = aPhrase;
	p->nextPhrase = nullptr;
	p->selected = 0;
	p->nextQuestStatus = QUEST_STATUS_NONE;
	p->quest = nullptr;

	return p;
}

Phrase* Phrase::AddOption(string aName, Phrase* aPhrase)
{
	if(nextPhrase != nullptr)
		return nextPhrase->AddOption(aName,aPhrase);

	options.push_back(aName);
	optionPhrase.push_back(aPhrase);

	return aPhrase;
}

void Phrase::AdvanceQuestStatus()
{
	quest->progress = nextQuestStatus;
}

bool Phrase::IsNextQuestStatus()
{
	return nextQuestStatus != QUEST_STATUS_NONE;
}

void Phrase::SetNextQuestStatus(int aNextQuestStatus, Quest* aQuest)
{
	nextQuestStatus = aNextQuestStatus;
	quest = aQuest;
}

Phrase::~Phrase()
{
	for(unsigned int i=0; i<options.size(); i++)
	{
		delete optionPhrase[i];
	}
	delete nextPhrase;
}

Phrase* Phrase::AddSubPhrase(string aPhrase)
{
	if(nextPhrase == nullptr)
	{
		nextPhrase = CreatePhrase(aPhrase);
		return nextPhrase;
	}
	else
	{
		return nextPhrase->AddSubPhrase(aPhrase);
	}
}

Phrase* Sentence::GetSentence(Character* aCharacter)
{
	if(!init)
	{
		Init();
		init = true;
	}

	if(aCharacter->GetAge() == AGE_CHILD)
		return phrases[0][rand()%phrases[0].size()];

	return phrases[aCharacter->GetProfession()][rand()%phrases[aCharacter->GetProfession()].size()];
}

void Sentence::Init()
{
	vector<Phrase*> tempPhrases;

	tempPhrases.clear();
	tempPhrases.push_back(Phrase::CreatePhrase("Mommy, I want a pony."));
	tempPhrases.push_back(Phrase::CreatePhrase("Mommy, I want a horsie."));
	phrases.push_back(tempPhrases);

	tempPhrases.clear();
	tempPhrases.push_back(Phrase::CreatePhrase("I really need to find something other than leafs for wiping up."));
	tempPhrases.push_back(Phrase::CreatePhrase("Death's assistant? It can't be a bad job... Can it?"));
	tempPhrases.push_back(Phrase::CreatePhrase("The Winchester brothers are in town. I have a bad feeling about it."));
	tempPhrases.push_back(Phrase::CreatePhrase("Horse poop can be interesting if you're bored for long enough."));
	tempPhrases.push_back(Phrase::CreatePhrase("What are stairways to heaven made of?"));
	tempPhrases.push_back(Phrase::CreatePhrase("Who let the goats out?"));
	phrases.push_back(tempPhrases);

	tempPhrases.clear();
	tempPhrases.push_back(Phrase::CreatePhrase("Hold right there citizen!"));
	tempPhrases.push_back(Phrase::CreatePhrase("That is closed for a reason!"));
	tempPhrases.push_back(Phrase::CreatePhrase("Show me your pockets citizen!"));
	tempPhrases.push_back(Phrase::CreatePhrase("Go back where you came from mister!"));
	tempPhrases.push_back(Phrase::CreatePhrase("Lame players not allowed here!"));
	phrases.push_back(tempPhrases);

	tempPhrases.clear();
	tempPhrases.push_back(Phrase::CreatePhrase("Zerrakian steel my ass!"));
	tempPhrases.push_back(Phrase::CreatePhrase("Who would need an armor with a sword like this?"));
	tempPhrases.push_back(Phrase::CreatePhrase("Devil may cry from this sword."));
	phrases.push_back(tempPhrases);

	tempPhrases.clear();
	tempPhrases.push_back(Phrase::CreatePhrase("My armor has a lifetime guarantee!"));
	tempPhrases.push_back(Phrase::CreatePhrase("Looks horrible, but it may save your life!"));
	tempPhrases.push_back(Phrase::CreatePhrase("Has anyone seen my hammer?"));
	phrases.push_back(tempPhrases);

	tempPhrases.clear();
	tempPhrases.push_back(Phrase::CreatePhrase("Who let the dogs out? It was me!"));

	/*
	Phrase* p = Phrase::CreatePhrase("I heard one time something about Mary");
	p->nextPhrase = Phrase::CreatePhrase("She liked sweet drinks with a palm");
	p->nextPhrase->nextPhrase = Phrase::CreatePhrase("And she was kidnapped by old and sick Dragon!");
	p->nextPhrase->nextPhrase->nextPhrase = Phrase::CreatePhrase("Boom!");
	Phrase* o = p->nextPhrase->nextPhrase->nextPhrase->nextPhrase
		= Phrase::CreatePhrase("End of story, go back to drinking this... thing");
	o->AddOption("Boooring...",Phrase::CreatePhrase("Not as boring as your mother"));
	o->AddOption("That's fantastic!",Phrase::CreatePhrase("I knew you'd like it!"));
	tempPhrases.push_back(p);
	*/

	tempPhrases.push_back(Phrase::CreatePhrase("Keep calm and finish your beer."));
	tempPhrases.push_back(Phrase::CreatePhrase("You shouldn't leave here sober."));
	tempPhrases.push_back(Phrase::CreatePhrase("I'm not drunk, I'm just following a snake."));
	phrases.push_back(tempPhrases);

	tempPhrases.clear();
	tempPhrases.push_back(Phrase::CreatePhrase("Potions, herbs, verbs, emotions. I've seen locomotions."));
	tempPhrases.push_back(Phrase::CreatePhrase("Who wants some punch?"));
	tempPhrases.push_back(Phrase::CreatePhrase("Do you believe in mana?"));
	tempPhrases.push_back(Phrase::CreatePhrase("Why do people always want to see my boobs?"));
	phrases.push_back(tempPhrases);

	tempPhrases.clear();
	tempPhrases.push_back(Phrase::CreatePhrase("Democracy is hypocrisy!"));
	tempPhrases.push_back(Phrase::CreatePhrase("All your gold will be spend in the name of profit. Profit, my son, come here!"));
	tempPhrases.push_back(Phrase::CreatePhrase("I'm your king. Kneel before me!"));
	tempPhrases.push_back(Phrase::CreatePhrase("If I had a daughter I would give her hand to a heroic knight."));
	phrases.push_back(tempPhrases);

	tempPhrases.clear();
	tempPhrases.push_back(Phrase::CreatePhrase("Are looking for a healer? Well here I am!"));
	tempPhrases.push_back(Phrase::CreatePhrase("Pray with me my children to our merciful Gods."));
	tempPhrases.push_back(Phrase::CreatePhrase("If you are wounded come closer."));
	tempPhrases.push_back(Phrase::CreatePhrase("The Book of Eli - limited edition."));
	phrases.push_back(tempPhrases);

	tempPhrases.clear();
	tempPhrases.push_back(Phrase::CreatePhrase("I have the best prices on this side of Cormyr!"));
	tempPhrases.push_back(Phrase::CreatePhrase("If you want to buy something, I have something to sell."));
	tempPhrases.push_back(Phrase::CreatePhrase("If you want to sell something... Well, you can try."));
	tempPhrases.push_back(Phrase::CreatePhrase("I may have something you need."));
	tempPhrases.push_back(Phrase::CreatePhrase("I can help you, if you have enough money."));
	phrases.push_back(tempPhrases);

	tempPhrases.clear();
	tempPhrases.push_back(Phrase::CreatePhrase("I can cook anything you want."));
	tempPhrases.push_back(Phrase::CreatePhrase("I'm a cook, not your mother. You must pay for food."));
	tempPhrases.push_back(Phrase::CreatePhrase("One bottle of wine, half a pig, some spices and two baskets of apples. Done."));
	tempPhrases.push_back(Phrase::CreatePhrase("Are you looking for a secret recipe?"));
	phrases.push_back(tempPhrases);

	tempPhrases.clear();
	tempPhrases.push_back(Phrase::CreatePhrase("All I need is a long piece of rope and a box."));
	tempPhrases.push_back(Phrase::CreatePhrase("Oh my, these packages are so heavy!"));
	tempPhrases.push_back(Phrase::CreatePhrase("What should I take?"));
	phrases.push_back(tempPhrases);
}

Sentence::Sentence()
{
}


Sentence::~Sentence()
{
}